/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package glamourbeautyclinic.personel;


import images.GlamourImage;
import java.awt.Point;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JInternalFrame;
import javax.swing.RowSorter;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
import util.DBConnection;

/**
 *
 * @author anh
 */
public class FrmStaffApp extends javax.swing.JInternalFrame {
    GlamourImage GI = new GlamourImage();
    //DBConnection dc = new DBConnection();
    DBConnection dc;
    ResultSet rs;
    Statement stmt;
    DefaultTableModel staffAppModel;
    
    /**
     * Creates new form FrmRelApp
     */
    public FrmStaffApp(DBConnection dc, JInternalFrame RelativeFrame, String staffName, String staffID) {
        initComponents();
        this.dc = dc;
        GI.addIconFor(this);
        this.setLocation(RelativeFrame.getX() + RelativeFrame.getWidth()+10, RelativeFrame.getY());
        RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tblStaffApp.getModel());
        tblStaffApp.setRowSorter(sorter);
        tblStaffApp.setComponentPopupMenu(pmnStaff_AppD);
        this.setTitle("Appointment of "+staffName);
        staffAppModel = (DefaultTableModel) tblStaffApp.getModel();
        staffAppModel.setRowCount(0);
        try {
            stmt = dc.con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
            rs = stmt.executeQuery("select AppDID,ServiceName,SttDetail from vw_full_app where StaffID='"+staffID+"'");
            while (rs.next()) {
                staffAppModel.addRow(new Object[]{rs.getString(1),rs.getString(2),rs.getString(3)});
            }
            tblStaffApp.setModel(staffAppModel);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pmnStaff_AppD = new javax.swing.JPopupMenu();
        mniRefresh = new javax.swing.JMenuItem();
        mniCancel = new javax.swing.JMenuItem();
        mniFinish = new javax.swing.JMenuItem();
        mniDelete = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        mniDetails = new javax.swing.JMenuItem();
        btnRefresh = new javax.swing.JButton();
        lblApp = new javax.swing.JLabel();
        lblSer = new javax.swing.JLabel();
        jspStaffApp = new javax.swing.JScrollPane();
        tblStaffApp = new javax.swing.JTable();

        mniRefresh.setText("Refresh");
        pmnStaff_AppD.add(mniRefresh);

        mniCancel.setText("Cancel");
        pmnStaff_AppD.add(mniCancel);

        mniFinish.setText("Finish1");
        pmnStaff_AppD.add(mniFinish);

        mniDelete.setText("Delete");
        pmnStaff_AppD.add(mniDelete);
        pmnStaff_AppD.add(jSeparator1);

        mniDetails.setText("Details");
        pmnStaff_AppD.add(mniDetails);

        btnRefresh.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnRefresh.setForeground(new java.awt.Color(0, 51, 51));
        btnRefresh.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Refresh.png"))); // NOI18N
        btnRefresh.setMnemonic('a');
        btnRefresh.setText("Refresh");
        btnRefresh.setToolTipText("Check all select combo box");
        btnRefresh.setBorder(null);
        btnRefresh.setContentAreaFilled(false);
        btnRefresh.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnRefresh.setMargin(new java.awt.Insets(6, 6, 6, 6));
        btnRefresh.setName(""); // NOI18N
        btnRefresh.setOpaque(true);
        btnRefresh.setPreferredSize(new java.awt.Dimension(59, 22));
        btnRefresh.setRolloverEnabled(false);

        lblApp.setForeground(new java.awt.Color(0, 51, 255));
        lblApp.setText("Appointment: 2");

        lblSer.setForeground(new java.awt.Color(0, 51, 255));
        lblSer.setText("Service: 4");

        setTitle("Appointment of <Staff name>");
        setName("StaffApp"); // NOI18N

        tblStaffApp.setForeground(new java.awt.Color(0, 102, 51));
        tblStaffApp.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"20140101-App001.01", "Hair cuts", "Finished"},
                {"20140101-App002.01", "Waxing", "Finished"},
                {"20140101-App005.01", "Hair dye", "Canceled"},
                {"20140201-App001.02", "Hair wash", "Pending"}
            },
            new String [] {
                "AppDID", "Service", "Status"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tblStaffApp.getTableHeader().setReorderingAllowed(false);
        tblStaffApp.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                tblStaffAppMousePressed(evt);
            }
        });
        jspStaffApp.setViewportView(tblStaffApp);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jspStaffApp, javax.swing.GroupLayout.DEFAULT_SIZE, 374, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jspStaffApp, javax.swing.GroupLayout.DEFAULT_SIZE, 268, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void tblStaffAppMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblStaffAppMousePressed
        Point point = evt.getPoint();
        int currentRow = tblStaffApp.rowAtPoint(point);
        tblStaffApp.setRowSelectionInterval(currentRow, currentRow);
    }//GEN-LAST:event_tblStaffAppMousePressed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnRefresh;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JScrollPane jspStaffApp;
    private javax.swing.JLabel lblApp;
    private javax.swing.JLabel lblSer;
    private javax.swing.JMenuItem mniCancel;
    private javax.swing.JMenuItem mniDelete;
    private javax.swing.JMenuItem mniDetails;
    private javax.swing.JMenuItem mniFinish;
    private javax.swing.JMenuItem mniRefresh;
    private javax.swing.JPopupMenu pmnStaff_AppD;
    private javax.swing.JTable tblStaffApp;
    // End of variables declaration//GEN-END:variables
}
